Yacon.TDispatch = function(conText){
	
	this.req = null;
	this.rsp = null;
	
	Yacon.apply(this,conText);
	
	this.self = this;
	
	this.adapter = null;

};

Yacon.TDispatch.Extend(Object,{
	
	postPage : function(){
		
		var self = this.self;
		
		this.url = Yacon.addUrlParam("lilyPageType", "1", this.url);
		
		this.url = getAbsolutePath(this.url);
		this.url = Yacon.addToken(this.url);
		
		$.ajax({
            type: "POST",
            url: this.url,
            processData: false,
            async: false,
            dataType: 'text', 
            success: function(data){           	
            	self.rsp = data;  
            }
        });
		
	},
	
	post: function(isAsync) {
		
		var self = this.self;
		
		if(!Yacon.isEmpty(this.req)){
			this.req = this.req.replace(/\n/g,"<br/br>");
			this.req = this.req.replace(/\r/g,"<br/br>");
		}
		
		self.url = getAbsolutePath(this.url);		
		self.url = Yacon.addToken(self.url);
		
		//this.req = this.req.encode();
		
		if(!isAsync){
			
			$.ajax({
	            type: "POST",
	            url: self.url,     
	            processData: false,
	            async: isAsync,
	            dataType: 'text',  
	            data: "switch_xml="+this.req,
	            success: function(data){           	 
	            	try{
	            		self.rsp = JSON.parse(data);
	            	}
	            	catch(err){
	            		self.rsp = window.eval("("+data+")")
	            	}
	            }
	        });
			
		}else{
			
			$.ajax({
	            type: "POST",
	            url: self.url,     
	            processData: false,
	            async: isAsync,
	            dataType: 'text', 
	            data: "switch_xml="+this.req,
	            beforeSend: function () {
	            	Yacon.callBackMethod(self.before);
                },
	            success: function(data){ 
	            	
	            	try{
	            		self.rsp = JSON.parse(data);
	            	}
	            	catch(err){
	            		self.rsp = window.eval("("+data+")")
	            	}
	            	       	
	            	self.dataSet.rsp = self.rsp;
	            	
	            	var typ = self.rsp.action.type;
	            	
	        		if(!Yacon.isEmpty(typ)){
	        			if(typ == "0" || typ == 0){
	        				alert(self.rsp.action.message);
	        			}
	        		}
	        		
	        		self.after.param[0].rsp = self.rsp;
	            	
	            	Yacon.callBackMethod(self.after);
	            },
	            error: function (e, jqxhr, settings, exception) {
	            	Yacon.callBackMethod(self.after);
                }
	        });
			
		}

	}
	
});